home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / desktop / sperm / sperm.c < prev    next >
C/C++ Source or Header  |  1992-12-20  |  4KB  |  145 lines

  1. //
  2. // SPERM - swimming sperm SPX library
  3. //
  4. // Version 1.0 12/18/92 Copyright (C) 1992 Hutchins Software
  5. // Author: Edward Hutchins
  6. // Revisions:
  7. //
  8.  
  9. #include "sperm.h"
  10.  
  11. //
  12. // globals
  13. //
  14.  
  15. GLOBAL HANDLE       hLibInst;                           // current instance
  16. GLOBAL INT          nSpermCnt;                          // number of colors
  17. GLOBAL BOOL         bEnabled;                           // SPX enable switch
  18. GLOBAL TRI          triBlank;                           // blank screen first
  19. GLOBAL CHAR         szAppName[] = "Screen Peace";       // saver app name
  20. GLOBAL CHAR         szSaverName[] = "Sperm";            // SPX name
  21. GLOBAL CHAR         szProfSpermCnt[] = "Sperm Count";   // profiler key
  22. GLOBAL CHAR         szProfEnabled[] = "Sperm On";       // profiler key
  23. GLOBAL CHAR         szProfBlank[] = "Sperm Blank";      // profiler key
  24.  
  25. //
  26. // GetProfileTri - get a tri-state variable from the profile
  27. //
  28.  
  29. TRI NEAR PASCAL GetProfileTri( LPSTR lpszKey )
  30. {
  31.     GLOBAL CHAR         szBuff[64];
  32.  
  33.     GetProfileString( szAppName, lpszKey, "u", szBuff, sizeof(szBuff) );
  34.     switch (szBuff[0])
  35.     {
  36.     case 'N': case 'n':
  37.         return( TRI_FALSE );
  38.     case 'Y': case 'y':
  39.         return( TRI_TRUE );
  40.     default:
  41.         return( TRI_UNSET );
  42.     }
  43. }
  44.  
  45. //
  46. // WriteProfileTri - write a tri-state variable to the profile
  47. //
  48.  
  49. BOOL NEAR PASCAL WriteProfileTri( LPSTR lpszKey, TRI tri )
  50. {
  51.     switch (tri)
  52.     {
  53.     case TRI_FALSE:
  54.         return( WriteProfileString( szAppName, lpszKey, "n" ) );
  55.     case TRI_TRUE:
  56.         return( WriteProfileString( szAppName, lpszKey, "y" ) );
  57.     default:
  58.         return( WriteProfileString( szAppName, lpszKey, "u" ) );
  59.     }
  60. }
  61.  
  62. //
  63. // WriteProfileInt - write an integer to the profile
  64. //
  65.  
  66. BOOL NEAR PASCAL WriteProfileInt( LPSTR lpszKey, INT nVal )
  67. {
  68.     GLOBAL CHAR         szBuff[64];
  69.  
  70.     wsprintf( szBuff, "%u", nVal );
  71.     return( WriteProfileString( szAppName, lpszKey, szBuff ) );
  72. }
  73.  
  74. //
  75. // LibMain - initialize the local data segment
  76. //
  77.  
  78. BOOL FAR PASCAL EXPORT LibMain( HINSTANCE hInstance, WORD wDataSeg,
  79.                                 WORD wHeapSize, LPSTR szCmdLine )
  80. {
  81.     hLibInst = hInstance;
  82.     nSpermCnt = GetProfileInt( szAppName, szProfSpermCnt, SPERM_MAX / 2 );
  83.     bEnabled = GetProfileTri( szProfEnabled );
  84.     triBlank = GetProfileTri( szProfBlank );
  85.     UnlockData( 0 );
  86.     return( TRUE );
  87. }
  88.  
  89. //
  90. // WEP - Windows Exit Procedure, clean up resources
  91. //
  92.  
  93. VOID FAR PASCAL EXPORT WEP( BOOL bSystemExit )
  94. {
  95. }
  96.  
  97. //
  98. // SaverInit - register with Screen Peace
  99. //
  100.  
  101. LPSTR FAR PASCAL EXPORT SaverInit( LPBOOL lpbEnabled )
  102. {
  103.     *lpbEnabled = bEnabled;
  104.     return( szSaverName );
  105. }
  106.  
  107. //
  108. // SaverDlgProc - dialog proc for user customization
  109. //
  110.  
  111. BOOL FAR PASCAL EXPORT SaverDlgProc( HWND hdlg, WORD mess, WORD wP, LONG lP )
  112. {
  113.     switch (mess)
  114.     {
  115.     case WM_INITDIALOG:
  116.         SetDlgItemInt( hdlg, IDD_S_SPERMCNT, nSpermCnt, FALSE );
  117.         SendDlgItemMessage( hdlg, IDD_S_ENABLE, BM_SETCHECK, bEnabled, 0 );
  118.         SendDlgItemMessage( hdlg, IDD_S_BLANK, BM_SETCHECK, triBlank, 0 );
  119.         return( TRUE );
  120.  
  121.     case WM_COMMAND:
  122.         switch (wP)
  123.         {
  124.         case IDOK:
  125.             nSpermCnt = GetDlgItemInt( hdlg, IDD_S_SPERMCNT, NULL, FALSE );
  126.             bEnabled = (BOOL)SendDlgItemMessage( hdlg, IDD_S_ENABLE, BM_GETCHECK, 0, 0 );
  127.             triBlank = (TRI)SendDlgItemMessage( hdlg, IDD_S_BLANK, BM_GETCHECK, 0, 0 );
  128.             WriteProfileTri( szProfEnabled, bEnabled );
  129.             if (bEnabled)
  130.             {
  131.                 WriteProfileInt( szProfSpermCnt, nSpermCnt );
  132.                 WriteProfileTri( szProfBlank, triBlank );
  133.             }
  134.             EndDialog( hdlg, TRUE );
  135.             return( TRUE );
  136.  
  137.         case IDCANCEL:
  138.             EndDialog( hdlg, FALSE );
  139.             return( TRUE );
  140.         }
  141.         break;
  142.     }
  143.     return( FALSE );
  144. }
  145.